<template>
    <a-modal :title="title" :visible="visible" class="pub-middle-dialog" @ok="handleOk" @cancel="visible = false">
        <a-table :pagination="false" :columns="columns" :data-source="tableData" row-key="id">
            <span slot="num" slot-scope="text, record, index">{{ index + 1 }}</span>
            <div slot="operation" slot-scope="text, record, index" class="pub-table-list-action">
                <span @click="handleEdit(record, 3)">查看</span>
            </div>
        </a-table>
    </a-modal>
</template>
<script>
import { historyList } from '@/api/material/materialMasterPlan/monthPlan'
export default {
    name: 'a' + Date.now(),
    props: {
        id: {
            type: String
        },
        title: {
            type: String,
            default: '历史记录选择'
        },
        btnCb: {
            type: Function
        }
    },
    data: function () {
        return {
            pageNo: 1,
            pageSize: 10,
            totalSize: 0,
            visible: false,
            tableData: [],
            columns: [
                {
                    title: '序号',
                    scopedSlots: { customRender: 'num' }
                },
                {
                    title: '变更人',
                    dataIndex: 'changeUser'
                },
                {
                    title: '变更时间',
                    dataIndex: 'sex'
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    scopedSlots: { customRender: 'operation' }
                }
            ]
        }
    },
    methods: {
        open: function () {
            this.visible = true
            this.list()
        },
        handleOk: function () {
            this.visible = false
        },
        list() {
            historyList({ id: this.id }).then(res => {
                this.tableData = res.data
                this.totalSize = res.totalElements
            })
        },
        handleEdit(record, state) {
            if (this.btnCb) {
                this.btnCb(record, state)
            } else {
                let obj = {
                    // row: record,
                    id: record && record.id || '',
                    state: state
                }
                this.handleOk();
                this.$emit("close", obj)
            }
        }
    }
}
</script>